<include file="public/shop_header"/>

<body>

<!--main-->
<style type="text/css">
body{ background:#f4f4f4;}
</style>
<div class="cpMain" style="padding-bottom:20px;">
  <div class="porder-detaState clearfix">
    <div class="word">
      <h3 class="t">
        <if condition="$order.order_status eq 0">待买家付款</if>
        <if condition="$order.order_status eq 1">待卖家发货</if>
        <if condition="$order.order_status eq 2">待买家收货</if>
        <if condition="$order.order_status eq 3"> 交易成功 </if>
        <if condition="$order.order_status eq -1">订单已取消</if>
      </h3>
      <if condition="$order.order_status eq 0">
        <div class="c">
          下单15分钟后，自动关闭
        </div>
      </if>
    </div>
    <div class="pic">
      <img src="__PUBLIC__/shop/images/dsh-img.jpg">
    </div>
  </div>
  <div class="porder-detaAdd clearfix">
    <div class="t clearfix">
      <span class="name fl">收货人：{$order.username}</span> <span class="tel fr">{$order.phone}</span>
    </div>
    <div class="c">
      收货地址：{$order.address}
    </div>
  </div>
  <div class="porder-item">
    <h3 class="porder-item-state">{$shop_order_status[$order['order_status']]}</h3>

    <volist name="order_goods" id="order_goods">
      <div class="porder-item-info clearfix">
        <div class="pic fl">
          <a href="{:U('Goods/goods_detail',array('item_id' => $order_goods.goods_id))}"><img src="{$order_goods.original_img}"></a>
        </div>
        <div class="word fr">
          <h3 class="t"><a href="{:U('Goods/goods_detail',array('item_id' => $order_goods.goods_id))}">{$order_goods.goods_name}</a><span class="price">￥{$order_goods.goods_price}</span></h3>
          <div class="f clearfix">
            <span class="guig fl">{$order_goods.spec_key_name}</span> <span class="num fr">X{$order_goods.goods_num}</span>
          </div>
        </div>
      </div>
    </volist>

  </div>
  <div class="porder-detaSpec">
    <dl class="clearfix" <if condition="$order.order_status neq 0">style="display: none"</if> >
    <dl class="clearfix">
      <dt>积分价格</dt>
      <dd>{$order.goods_price * 10}积分</dd>
    </dl>
    <dl class="clearfix">
      <dt>商品价格</dt>
      <dd><span class="c-orange">￥{$order.goods_price}</span></dd>
    </dl>
    <dl class="clearfix" <if condition="$order.distribution_way eq 2">style="display: none"</if> >
      <dt>运  费</dt>
      <dd><span class="c-orange">商家包邮</span></dd>
    </dl>
  </div>
  <div class="porder-detaReal clearfix">
    <div class="dt fl">
      实付款
    </div>
    <div class="dd fr">
      <strong class="c-orange">￥{$order.goods_price}</strong>{$order.goods_price * 10}积分
    </div>
  </div>
  <div class="porder-detaProcess">
    <p>订单编号：{$order.order_sn}</p>
    <p>创建时间：{:$order.add_time > 0 ? date('Y-m-d H:i:s',$order.add_time) : ''}</p>
    <if condition="$order.order_status gt 0"><p>支付时间：{:$order.pay_time > 0 ? date('Y-m-d H:i:s',$order.pay_time) : ''}</p></if>
    <if condition="$order.order_status gt 1"><p>发货时间：{:$order.delivery_time > 0 ? date('Y-m-d H:i:s',$order.delivery_time) : ''}</p></if>
    <if condition="$order.order_status gt 2"><p>成交时间：{:$order.turnover_time > 0 ? date('Y-m-d H:i:s',$order.turnover_time) : ''}</p></if>

  </div>
  <div class="porder-item-opera clearfix">
    <a href="tel:{$config.index_phone}" class="o-btn">联系客服</a>
    <a href="{:U('Order/shop_index')}" class="o-btn">返回列表</a>
    <if condition="$order.order_status eq 0">
      <!--<a href="javascript:;" class="o-btn">取消订单</a>-->
      <a href="javascript:;" class="o-btn" onclick="shop_pay_order()">付款</a>
    </if>
    <if condition="$order.order_status eq 2">
      <a href="javascript:;" class="o-btn" onclick="confirm_receipt()">确认收货</a>
    </if>

    <if condition="$order.order_status eq 3 and $order.level elt 0">
      <a href="{:U('Order/evaluate',['id'=>$order.order_id])}" class="o-btn" >订单评价</a>
    </if>

  </div>
</div>
<!--main End-->

<script>
    //订单提交支付
    function shop_pay_order() {
        var item_id = "{$order.order_id}";
        $.ajax({
            type : "POST",
            url:"/home/payment/shop_pay_order.html",
            data : {item_id:item_id},// 你的formid 搜索表单 序列化提交
            dataType:'json',
            success: function(result){
                if (result.status == 200){
                    //还需要支付，调取微信支付
                    function onBridgeReady(){
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest', {
                                "appId":result.result.appId,     //公众号名称，由商户传入
                                "timeStamp":result.result.timeStamp,         //时间戳，自1970年以来的秒数
                                "nonceStr":result.result.nonceStr, //随机串
                                "package":result.result.package,
                                "signType":"MD5",         //微信签名方式：
                                "paySign":result.result.paySign //微信签名
                            },
                            function(res){
                                if(res.err_msg == "get_brand_wcpay_request:ok" ){
                                    location.href = '/home/order/shop_index.html';
                                }
                                if(res.err_msg == "get_brand_wcpay_request:cancel" ){
                                    location.href = '/home/order/shop_index.html';
                                }
                                if(res.err_msg == "get_brand_wcpay_request:fail" ){
                                    location.href = '/home/order/shop_index.html';
                                }
                            });
                    }
                    if (typeof WeixinJSBridge == "undefined"){
                        if( document.addEventListener ){
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                        }else if (document.attachEvent){
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                        }
                    }else{
                        onBridgeReady();
                    }
                }else{
                    if (result.status == 400){
                        //支付成功
                        layer.msg(result.msg,{icon:1,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                    }else{
                        //遇到错误
                        layer.msg(result.msg,{icon:2,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                    }
                }
            }
        });
    }


    //确认收货
    function confirm_receipt(){
        var item_id = "{$order.order_id}";
        $.ajax({
            type : "POST",
            url:"/Home/Order/confirm_receipt.html",
            data : {item_id:item_id},// 你的formid 搜索表单 序列化提交
            dataType:'json',
            success: function(result){
                if (result.status == 200){
                    layer.msg(result.msg,{icon:1,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                }else{
                    layer.msg(result.msg,{icon:2,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                }
            }
        });
    }
</script>

</body>
</html>
